/*
 * Example Web Application
 */
package webapp;

import java.util.Scanner;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;


/**
 * Launch the web server and the web application.
 */
public class Launcher {
	public static void main(String[] args) throws Exception {
		Server server = new Server(8080);
		
		// Set up servlet context
		ServletContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
		servletContext.setContextPath("/");

		// Servlets
		servletContext.addServlet(new ServletHolder(new ExampleServlet()), "/example");
		servletContext.addServlet(new ServletHolder(new InventoryServlet()), "/inventory/*");
		
		// Add the servlet context
		server.setHandler(servletContext);

		server.start();

		waitForQuit();
		
		server.stop();
		server.join();
		
		System.out.println("Server has shut down");
	}

	private static void waitForQuit() {
		System.out.println("Type 'quit' to shut down the server");
		Scanner keyboard = new Scanner(System.in);
		while (true) {
			String line = keyboard.nextLine();
			if (line == null || line.equals("quit")) {
				break;
			}
		}
	}
}
